//
//  PermanceMercMsgVM.swift
//  kxf
//
//  Created by Mac on 2024/3/27.
//

import Foundation
import UIKit

class PermanceMercMsgVM: UIView {
    
    let selfHeight = kFitWidth(271)

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: kFitWidth(1), y: frame.origin.y, width: kFitWidth(373), height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(8)
        self.clipsToBounds = true
        
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var titleVm : RegisterViewHeadTitleVM = {
        let vm = RegisterViewHeadTitleVM.init(frame: .zero)
        vm.titleLabel.text = "客户"
        return vm
    }()
    lazy var bgImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_agent_detail_bg")
        
        return img
    }()
    
    lazy var rowOneFirstLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowOneFirstLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "新增直接服务商"
        
        return lab
    }()
    lazy var lineViewRowOneFirst : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    lazy var rowOneSecondLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowOneSecondLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "新增直接商户"
        
        return lab
    }()
    lazy var lineViewRowOneSecond : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    lazy var rowOneThirdLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowOneThirdLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "累计间接服务商"
        
        return lab
    }()
    
    
    lazy var rowTwoFirstLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowTwoFirstLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "累计直接服务商"
        
        return lab
    }()
    lazy var lineViewRowTwoFirst : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    lazy var rowTwoSecondLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowTwoSecondLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "累计直接商户"
        
        return lab
    }()
    lazy var lineViewRowTwoSecond : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    lazy var rowTwoThirdLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowTwoThirdLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "累计间接服务商"
        
        return lab
    }()
    
    
    lazy var rowThreeFirstLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowThreeFirstLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "新增间接服务商"
        
        return lab
    }()
    lazy var lineViewRowThreeFirst : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    lazy var rowThreeSecondLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rowThreeSecondLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "新增间接商户"
        
        return lab
    }()
}

extension PermanceMercMsgVM{
    func updateUI(dict:NSDictionary)  {
        rowOneFirstLabel.text = "\(dict["directSubAgentNumber"]as? Int ?? 0)"
        rowOneSecondLabel.text = "\(dict["directSubMerchantNumber"]as? Int ?? 0)"
        rowOneThirdLabel.text = "\(dict["cumulativeIndirectSubAgentNumber"]as? Int ?? 0)"
        rowTwoFirstLabel.text = "\(dict["cumulativeDirectSubAgentNumber"]as? Int ?? 0)"
        rowTwoSecondLabel.text = "\(dict["cumulativeDirectSubMerchantNumber"]as? Int ?? 0)"
        rowTwoThirdLabel.text = "\(dict["cumulativeIndirectSubMerchantNumber"]as? Int ?? 0)"
        rowThreeFirstLabel.text = "\(dict["indirectSubAgentNumber"]as? Int ?? 0)"
        rowThreeSecondLabel.text = "\(dict["indirectSubMerchantNumber"]as? Int ?? 0)"
    }
}

extension PermanceMercMsgVM{
    func initUI() {
        addSubview(titleVm)
        addSubview(bgImgView)
        bgImgView.addSubview(rowOneFirstLabel)
        bgImgView.addSubview(rowOneFirstLab)
        bgImgView.addSubview(lineViewRowOneFirst)
        bgImgView.addSubview(rowOneSecondLabel)
        bgImgView.addSubview(rowOneSecondLab)
        bgImgView.addSubview(lineViewRowOneSecond)
        bgImgView.addSubview(rowOneThirdLabel)
        bgImgView.addSubview(rowOneThirdLab)
        
        bgImgView.addSubview(rowTwoFirstLabel)
        bgImgView.addSubview(rowTwoFirstLab)
        bgImgView.addSubview(lineViewRowTwoFirst)
        bgImgView.addSubview(rowTwoSecondLabel)
        bgImgView.addSubview(rowTwoSecondLab)
        bgImgView.addSubview(lineViewRowTwoSecond)
        bgImgView.addSubview(rowTwoThirdLabel)
        bgImgView.addSubview(rowTwoThirdLab)
        
        bgImgView.addSubview(rowThreeFirstLabel)
        bgImgView.addSubview(rowThreeFirstLab)
        bgImgView.addSubview(lineViewRowThreeFirst)
        bgImgView.addSubview(rowThreeSecondLabel)
        bgImgView.addSubview(rowThreeSecondLab)
        
        setConstrait()
    }
    func setConstrait() {
        let labelWidth = kFitWidth(90)
        let leftGapOne = kFitWidth(15)
        let leftGapTwo = kFitWidth(131)
        let leftGapThree = kFitWidth(250)
        
        bgImgView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(13))
            make.right.equalTo(kFitWidth(-13))
            make.top.equalTo(kFitWidth(50))
            make.height.equalTo(kFitWidth(206))
        }
        rowOneFirstLabel.snp.makeConstraints { make in
            make.left.equalTo(leftGapOne)
            make.width.equalTo(labelWidth)
            make.top.equalTo(kFitWidth(15))
        }
        rowOneFirstLab.snp.makeConstraints { make in
            make.left.equalTo(leftGapOne)
            make.width.equalTo(labelWidth)
            make.top.equalTo(rowOneFirstLabel.snp.bottom).offset(kFitWidth(2))
        }
        rowOneSecondLabel.snp.makeConstraints { make in
            make.top.width.equalTo(rowOneFirstLabel)
            make.left.equalTo(leftGapTwo)
        }
        rowOneSecondLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneSecondLabel)
            make.centerY.lessThanOrEqualTo(rowOneFirstLab)
        }
        rowOneThirdLabel.snp.makeConstraints { make in
            make.left.equalTo(leftGapThree)
            make.top.width.equalTo(rowOneFirstLabel)
        }
        rowOneThirdLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneThirdLabel)
            make.centerY.lessThanOrEqualTo(rowOneFirstLab)
        }
        rowTwoFirstLabel.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneFirstLabel)
            make.top.equalTo(kFitWidth(77))
        }
        rowTwoFirstLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowTwoFirstLabel)
            make.top.equalTo(rowTwoFirstLabel.snp.bottom).offset(kFitWidth(2))
        }
        rowTwoSecondLabel.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneSecondLabel)
            make.centerY.lessThanOrEqualTo(rowTwoFirstLabel)
        }
        rowTwoSecondLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowTwoSecondLabel)
            make.centerY.lessThanOrEqualTo(rowTwoFirstLab)
        }
        rowTwoThirdLabel.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneThirdLabel)
            make.centerY.lessThanOrEqualTo(rowTwoFirstLabel)
        }
        rowTwoThirdLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowTwoThirdLabel)
            make.top.equalTo(rowTwoFirstLab)
        }
        rowThreeFirstLabel.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneFirstLabel)
            make.top.equalTo(kFitWidth(139))
        }
        rowThreeFirstLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowThreeFirstLabel)
            make.top.equalTo(rowThreeFirstLabel.snp.bottom).offset(kFitWidth(2))
        }
        rowThreeSecondLabel.snp.makeConstraints { make in
            make.left.width.equalTo(rowOneSecondLabel)
            make.top.equalTo(rowThreeFirstLabel)
        }
        rowThreeSecondLab.snp.makeConstraints { make in
            make.left.width.equalTo(rowThreeSecondLabel)
            make.centerY.lessThanOrEqualTo(rowThreeFirstLab)
        }
        lineViewRowOneFirst.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(111))
            make.top.equalTo(kFitWidth(30))
            make.width.equalTo(kFitWidth(1))
            make.height.equalTo(kFitWidth(17))
        }
        lineViewRowOneSecond.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(235))
            make.top.width.height.equalTo(lineViewRowOneFirst)
        }
        lineViewRowTwoFirst.snp.makeConstraints { make in
            make.left.width.height.equalTo(lineViewRowOneFirst)
            make.top.equalTo(kFitWidth(92))
        }
        lineViewRowTwoSecond.snp.makeConstraints { make in
            make.left.width.height.equalTo(lineViewRowOneSecond)
            make.centerY.lessThanOrEqualTo(lineViewRowTwoFirst)
        }
        lineViewRowThreeFirst.snp.makeConstraints { make in
            make.left.width.height.equalTo(lineViewRowOneFirst)
            make.top.equalTo(kFitWidth(151))
        }
    }
}
